#include "GfxEntitySkybox.h"

CGfxEntitySkybox::CGfxEntitySkybox(void): CGfxEntityModel(){}

CGfxEntitySkybox::~CGfxEntitySkybox(void){}

void CGfxEntitySkybox::doRender()
{
	D3DXMATRIX matView;
	D3DXMATRIX matViewSave;
	D3DXMATRIX matWorld;

	//get the old view matrix
	VIS->getDevice()->GetTransform(D3DTS_VIEW, &matViewSave);

	//alter the view matrix to center the skybox
	matView=matViewSave;
	matView._41=0.0f;
	matView._42=-0.4f;
	matView._43=0.0f;

	VIS->getDevice()->SetTransform(D3DTS_VIEW, &matView);

	//set a default world matrix
	D3DXMatrixIdentity(&matWorld);
	VIS->getDevice()->SetTransform(D3DTS_WORLD, &matWorld);

	// Disable the z buffer
	VIS->getDevice()->SetRenderState( D3DRS_ZENABLE, FALSE );
	VIS->getDevice()->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );

	// Disable lighting
	VIS->getDevice()->SetRenderState( D3DRS_LIGHTING, FALSE );

	//render the sky box
	for(DWORD i=0; i<m_numMaterials; i++)
	{
		//set the material and texture for this subset
		VIS->getDevice()->SetMaterial(&m_meshMaterials[i]);
		VIS->getDevice()->SetTexture(0, m_meshTextures[i]);

		//draw the mesh subset
		m_mesh->DrawSubset(i);
	}

	// Enable the z buffer
	VIS->getDevice()->SetRenderState( D3DRS_ZENABLE, true );
	VIS->getDevice()->SetRenderState( D3DRS_ZWRITEENABLE, true );

	// Enable lighting
	VIS->getDevice()->SetRenderState( D3DRS_LIGHTING, true );

	//restor the orginial view matrix
	VIS->getDevice()->SetTransform(D3DTS_VIEW, &matViewSave);

}